#!/usr/bin/php
<?php
/**
 * DolphinGTK - phpGtk framework
 *
 * @package    DolphinGTK
 * @author     Askarov Ruslan
 * @copyright  Askarov Ruslan (c) 2010.
 * @link       http://groups.google.com/group/dolphingtk
 * @license    http://www.opensource.org/licenses/gpl-license.php GPL
 * @version    0.1
 * @since      PHP v.: 5.2.1
 * @subpackage desktop
 * @category   main
 * @filesource
 */

define('BASE_DIR', rtrim(str_replace('\\', '/', dirname(__FILE__)), '/'). '/');
include BASE_DIR . 'library/functions.php';

load('widgets');
load('window');
load('sqlite');
load('tabber');
load('mysql');
load('table');
load('tray');
load('menu');
load('os');

#---------------------------------------------------------------------------#
$menu = array();

$menu[ i18n('File') ] = array(
  array( i18n('Add new host'), array('Apache', 'prompt_win'), 'ctrl+m', 'add' ),
  array( i18n('Add ftp user'), array('Ftpd','add_user'), 'ctrl+n', 'add' ),
  array( i18n('Ftp preferences'), array('Ftpd','preferences'), 'ctrl+p', 'preferences' ),
  array( ),
  array( i18n('Program screenshot'), array('Screenshot', 'create', 'program'), 'alt+p', 'copy' ),
  array( i18n('Desktop screenshot'), array('Screenshot', 'create', 'desktop'), 'alt+d', 'copy' ),
  array( ),
  array( i18n('Hide Window'), array('Tray', 'hide_or_show'), false, 'clear' ),
  array( i18n('Quit'), 'if_quit', 'ctrl+q', 'quit' )
);

$menu[ i18n('Manual') ] = array(
  array( i18n('About'), 'about', 'ctrl+F1', 'about' ),
  array( i18n('Help'), 'help', 'F1', 'help' ),
);

$menu[ i18n('Quit') ] = array('if_quit');

#---------------------------------------------------------------------------#
$tray_menu = array(
  array( i18n('Help'), 'help', false, 'help' ),
  array( i18n('About'), 'about', false, 'about'   ),
  array( ),
  array( i18n('Hide/Show'),  array('Tray', 'hide_or_show'), false, 'close' ),
  array( i18n('Quit'), 'if_quit', false, 'quit' )
);
#---------------------------------------------------------------------------#

Win::close_if_copy();
Win::close_terms(true);
Win::create();
Win::state_save();

if( Win::$os == 'linux' )
{
  $user = OS::exec('whoami');

  if( $user != 'root' ) {
    Win::alert(
      'Security', i18n('Are you root? Use sudo or gksu prefix.')
    );
    exit;
  }
}

Win::title('DolphinGTK / Ftp+Apache');
Win::size(315,425);
Win::icon('images/dolphin.png');
Win::on_key('my_key');
Win::menu($menu);
Win::load_tab('apache', 'Apache host');
Win::load_tab('ftpd', 'FTP users');
Win::load('control');
Win::load('copyright');
Win::statusbar( i18n('Ready ...') );
Win::show(true);
Win::on_quit('if_quit');

Tray::create();
Tray::tooltips('DolphinGTK v.0.1 - Apache Host control');
Tray::icon( 'images/dolphin.png' );
Tray::menu( $tray_menu, true );

Win::main();


class Screenshot
{
  public function create( $action )
  {
    $values = Win::prompt( array('Введите имя файла'=>''), 200, 'Save Screenshot' );
    if( !empty($values[0]) ) {
      if( $action == 'program' ) {
        Win::screenshot(BASE_DIR.$values[0].'.png','png');
      } else {
        OS::screenshot(BASE_DIR.$values[0].'.png','png');
      }
      Win::alert(WIN_TITLE,'Скриншот сохранен в "'.BASE_DIR.$values[0].'.png" ');
    }
  }
}


function if_quit()
{
  $conf = Win::confirm(
    WIN_TITLE, i18n('Are you sure?')
  );

  if( $conf === true ) {
    Win::quit();
    return false;
  }

  return true;
}


function about()
{
  $data = array(
  'program_name'        => 'DolphinGTK',
  'version'             => 'v.0.1',
  'comments'            => 'php-gtk framework',
  'copyright'           => 'Copyright (C) 2010 Askarov Ruslan',
  'website'             => 'http://groups.google.com/group/dolphingtk',
  'authors'             => array('GoTLiuM InSPiRiT(Аскаров Руслан) <gotlium@gmail.com>'),
  'artists'             => array('GoTLiuM InSPiRiT(Аскаров Руслан) <gotlium@gmail.com>'),
  'documenters'         => array('GoTLiuM InSPiRiT(Аскаров Руслан) <gotlium@gmail.com>'),
  'translator_credits'  => 'GoTLiuM InSPiRiT(Аскаров Руслан) <gotlium@gmail.com>',
  'license'             => 'http://www.opensource.org/licenses/gpl-license.php GPL'
  );

  Win::about($data);
}


function help() {
  Win::alert(
    WIN_TITLE, i18n('Справка недоступна!'),
    'help'
  );
}


function my_key( $key ) {
  if( $key == 65307 ) {
    Tray::hide_or_show();
  }
}
?>